package com.xuan.task.utils;



import com.xuan.task.domain.WordPracticeFile;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * FileName: WordFileTypeUtils
 * Author:   xuan zongjun
 * Date:     2019/9/2 15:08
 * Description:  计算：记忆值、艾宾浩斯，判断是巩固词汇、熟练词汇、印象词汇、模糊词汇、遗忘词汇
 */


public class WordFileTypeUtils {

    public static  void setWordFileType(List<WordPracticeFile> wordPracticeFileList) {
        //循环列表计算

        for (WordPracticeFile wordPracticeFile : wordPracticeFileList) {
            //计算时间,单位小时= 当前系统时间 - 当前练习时间
            long learnTime = wordPracticeFile.getCurrentLearnTime().getTime() / 1000;
            long localTime = new Date().getTime() / 1000;
            long hour = (localTime - learnTime) / 60 / 60;
            double aiBinZhi = 0;
            //计算艾宾浩斯值 = 1- 0.56* 时间^0.06
            if (hour == 0) {
                aiBinZhi = 1;
            } else if (hour == 1) {
                aiBinZhi = 0.44;
            } else {
                aiBinZhi = 1 - 0.56 * Math.pow( hour, 0.06 );
                BigDecimal bigDecimal = new BigDecimal( aiBinZhi );
                aiBinZhi = bigDecimal.setScale( 10, BigDecimal.ROUND_HALF_UP ).doubleValue();
            }

            //计算记忆值 =  艾宾浩斯 * 记忆加权值 * 初始记忆值
            double memoryWeight = wordPracticeFile.getMemoryWeight();
            double memoryValue = aiBinZhi * memoryWeight * wordPracticeFile.getInitMemoryWeight();

            //根据记忆加权值 和 记忆值 判断是哪些库？ 1 巩固 2 熟练 3 印象 4 模糊 5 遗忘
            if (memoryWeight > 5 && memoryWeight <= 11) {
                wordPracticeFile.setType( 1 );
            } else if (memoryWeight > 3 && memoryWeight <= 5) {
                wordPracticeFile.setType( 2 );
            } else if (memoryWeight > 1 && memoryWeight <= 3) {
                wordPracticeFile.setType( 3 );
            } else if (memoryWeight == 1 && memoryValue > 40) {
                wordPracticeFile.setType( 4 );
            } else if (memoryWeight == 1 && memoryValue < 40) {
                wordPracticeFile.setType( 5 );
            }
        }
    }
}
